<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="主键id" prop="pharmacyId">
        <el-input
          v-model="queryParams.pharmacyId"
          placeholder="请输入主键id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="医馆图片" prop="pharmacyImg">-->
<!--        <el-input-->
<!--          v-model="queryParams.pharmacyImg"-->
<!--          placeholder="请输入医馆图片"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="医馆视频" prop="pharmacyVideo">-->
<!--        <el-input-->
<!--          v-model="queryParams.pharmacyVideo"-->
<!--          placeholder="请输入医馆视频"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="医馆名称" prop="pharmacyName">
        <el-input
          v-model="queryParams.pharmacyName"
          placeholder="请输入医馆名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医馆地址" prop="pharmacyAddress">
        <el-input
          v-model="queryParams.pharmacyAddress"
          placeholder="请输入医馆地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系人" prop="contactPersion">
        <el-input
          v-model="queryParams.contactPersion"
          placeholder="请输入联系人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="contactPhone">
        <el-input
          v-model="queryParams.contactPhone"
          placeholder="请输入联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="研学基地编号" prop="pharmacyNumber">
        <el-input
          v-model="queryParams.pharmacyNumber"
          placeholder="请输入研学基地编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="临床特长" prop="speciality">
        <el-input
          v-model="queryParams.speciality"
          placeholder="请输入临床特长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yljf:pharmacy:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yljf:pharmacy:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yljf:pharmacy:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yljf:pharmacy:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="pharmacyList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="pharmacyId" />
      <el-table-column label="医馆图片" align="center" prop="pharmacyImg" >
        <template slot-scope="scope">
          <img :src="setImgUrl(scope.row.pharmacyImg)" alt="" width="100%"/>
        </template>
      </el-table-column>
      <el-table-column width="220" label="医馆视频" align="center" prop="pharmacyVideo" >
        <template slot-scope="scope">
          <el-link class="cell-content" type="primary" :href="setImgUrl(scope.row.pharmacyVideo)" target="_blank">{{scope.row.pharmacyVideo}}</el-link>
        </template>
      </el-table-column>
      <el-table-column width="120" label="医馆名称" align="center" prop="pharmacyName" >
        <template slot-scope="scope">
          <div class="cell-content">{{scope.row.pharmacyName}}</div>
        </template>
      </el-table-column>
      <el-table-column width="180" label="医馆地址" align="center" prop="pharmacyAddress" >
        <template slot-scope="scope">
          <div class="cell-content">{{scope.row.pharmacyAddress}}</div>
        </template>
      </el-table-column>
      <el-table-column label="联系人" align="center" prop="contactPersion" />
      <el-table-column width="120" label="联系电话" align="center" prop="contactPhone" />
      <el-table-column width="120" label="研学基地编号" align="center" prop="pharmacyNumber" />
      <el-table-column width="150" label="临床特长" align="center" prop="speciality" />
      <el-table-column width="220" label="门诊简介" align="center" prop="remark" >
        <template slot-scope="scope">
          <div class="cell-content">{{scope.row.remark.replace(/<[^>]*>/g, '')}}</div>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yljf:pharmacy:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yljf:pharmacy:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改门诊医堂对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="主键id" prop="pharmacyId">
          <el-input v-model="form.pharmacyId" placeholder="请输入主键id" />
        </el-form-item>
        <el-form-item label="医馆图片" prop="pharmacyImg">
          <el-input v-model="form.pharmacyImg" placeholder="请输入医馆图片" />
        </el-form-item>
        <el-form-item label="医馆视频" prop="pharmacyVideo">
          <el-input v-model="form.pharmacyVideo" placeholder="请输入医馆视频" />
        </el-form-item>
        <el-form-item label="医馆名称" prop="pharmacyName">
          <el-input v-model="form.pharmacyName" placeholder="请输入医馆名称" />
        </el-form-item>
        <el-form-item label="医馆地址" prop="pharmacyAddress">
          <el-input v-model="form.pharmacyAddress" placeholder="请输入医馆地址" />
        </el-form-item>
        <el-form-item label="联系人" prop="contactPersion">
          <el-input v-model="form.contactPersion" placeholder="请输入联系人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="contactPhone">
          <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="研学基地编号" prop="pharmacyNumber">
          <el-input v-model="form.pharmacyNumber" placeholder="请输入研学基地编号" />
        </el-form-item>
        <el-form-item label="临床特长" prop="speciality">
          <el-input v-model="form.speciality" placeholder="请输入临床特长" />
        </el-form-item>
        <el-form-item label="门诊简介">
          <editor v-model="form.remark" :min-height="192"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPharmacy, getPharmacy, delPharmacy, addPharmacy, updatePharmacy } from "@/api/yljf/pharmacy";

export default {
  name: "Pharmacy",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 门诊医堂表格数据
      pharmacyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pharmacyId: null,
        pharmacyImg: null,
        pharmacyVideo: null,
        pharmacyName: null,
        pharmacyAddress: null,
        contactPersion: null,
        contactPhone: null,
        pharmacyNumber: null,
        speciality: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询门诊医堂列表 */
    getList() {
      this.loading = true;
      listPharmacy(this.queryParams).then(response => {
        this.pharmacyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        pharmacyId: null,
        pharmacyImg: null,
        pharmacyVideo: null,
        pharmacyName: null,
        pharmacyAddress: null,
        contactPersion: null,
        contactPhone: null,
        pharmacyNumber: null,
        speciality: null,
        remark: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.pharmacyId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加门诊医堂";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const pharmacyId = row.pharmacyId || this.ids
      getPharmacy(pharmacyId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改门诊医堂";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.pharmacyId != null) {
            updatePharmacy(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPharmacy(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const pharmacyIds = row.pharmacyId || this.ids;
      this.$modal.confirm('是否确认删除门诊医堂编号为"' + pharmacyIds + '"的数据项？').then(function() {
        return delPharmacy(pharmacyIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yljf/pharmacy/export', {
        ...this.queryParams
      }, `pharmacy_${new Date().getTime()}.xlsx`)
    },
    setImgUrl(url){
      if(url.indexOf('http://') == 0 || url.indexOf('https://') == 0){
        return url
      } else {
        return process.env.VUE_APP_BASE_API+url
      }

    },
  }
};
</script>
<style lang="scss" scoped>
.cell-content{
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 3; /* 限制行数为3 */
      overflow: hidden;
  }

  ::v-deep{
    .el-form-item__label{
      width: initial !important;
    }
  }
</style>
